class TestCompound extends Test
{
    public constructor(sprite:DebugDraw)
    {
        super(sprite);
        this.createScene();
    }

    private createScene():void
    {
        let bd:Box2D.Dynamics.b2BodyDef;
        let body:Box2D.Dynamics.b2Body;
        let i:number;
        let x:number;

        {
            let cd1:Box2D.Collision.Shapes.b2CircleShape = new Box2D.Collision.Shapes.b2CircleShape();
            cd1.SetRadius(15.0 / this.m_physScale);
            cd1.SetLocalPosition( new Box2D.Common.Math.b2Vec2(-15 / this.m_physScale, 15 / this.m_physScale));

            let cd2:Box2D.Collision.Shapes.b2CircleShape = new Box2D.Collision.Shapes.b2CircleShape();
            cd2.SetRadius(15 / this.m_physScale);
            cd2.SetLocalPosition(new Box2D.Common.Math.b2Vec2(15 / this.m_physScale, 15 / this.m_physScale));

            bd = new Box2D.Dynamics.b2BodyDef();
            bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
            for(i = 0; i < 5; i++)
            {
                x = 320 + Box2D.Common.Math.b2Math.RandomRange(-3.0, 3.0);
                bd.position.Set((x+ 150) / this.m_physScale,(31.5 + 75 * -i + 300) / this.m_physScale);
                bd.angle = Box2D.Common.Math.b2Math.RandomRange( -Math.PI, Math.PI);
                body = this.m_world.CreateBody(bd);
                body.CreateFixture2(cd1,2.0);
                body.CreateFixture2(cd2, 0.0);
            }
        }
        {
            let pd1:Box2D.Collision.Shapes.b2PolygonShape = new Box2D.Collision.Shapes.b2PolygonShape();
            pd1.SetAsBox(7.5 / this.m_physScale, 15.0 / this.m_physScale);

            let pd2:Box2D.Collision.Shapes.b2PolygonShape = new Box2D.Collision.Shapes.b2PolygonShape();
            pd2.SetAsOrientedBox(7.5 / this.m_physScale, 15.0 / this.m_physScale, new Box2D.Common.Math.b2Vec2(0, -15 / this.m_physScale), 0.5 * Math.PI);

            bd = new Box2D.Dynamics.b2BodyDef();
            bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;

            for(i = 0; i < 5; i++)
            {
                x = 320 + Box2D.Common.Math.b2Math.RandomRange(-3, 3);
                bd.position.Set((x-150)/this.m_physScale, (31.5 + 75 * -i + 300)/ this.m_physScale);
                bd.angle = Box2D.Common.Math.b2Math.RandomRange(-Math.PI, Math.PI);
                body = this.m_world.CreateBody(bd);
                body.CreateFixture2(pd1,2.0);
                body.CreateFixture2(pd2,2.0);
            }
        }
        {
            let xf1:Box2D.Common.Math.b2Transform = new Box2D.Common.Math.b2Transform();
            xf1.R.Set(0.3524 * Math.PI);
            xf1.position = Box2D.Common.Math.b2Math.MulMV(xf1.R, new Box2D.Common.Math.b2Vec2(1.0,0.0));

            let sd1:Box2D.Collision.Shapes.b2PolygonShape = new Box2D.Collision.Shapes.b2PolygonShape();
            sd1.SetAsArray([
                Box2D.Common.Math.b2Math.MulX(xf1, new Box2D.Common.Math.b2Vec2(-30 / this.m_physScale, 0)),
                Box2D.Common.Math.b2Math.MulX(xf1, new Box2D.Common.Math.b2Vec2(30 / this.m_physScale, 0)),
                Box2D.Common.Math.b2Math.MulX(xf1, new Box2D.Common.Math.b2Vec2(0, 15 / this.m_physScale))
            ])
            
            let xf2:Box2D.Common.Math.b2Transform = new Box2D.Common.Math.b2Transform();
            xf2.R.Set(-0.3524 * Math.PI);
            xf2.position = Box2D.Common.Math.b2Math.MulMV(xf2.R, new Box2D.Common.Math.b2Vec2(-30 / this.m_physScale, 0));

            let sd2:Box2D.Collision.Shapes.b2PolygonShape = new Box2D.Collision.Shapes.b2PolygonShape();
            sd2.SetAsArray([
                Box2D.Common.Math.b2Math.MulX(xf2, new Box2D.Common.Math.b2Vec2(-30 / this.m_physScale, 0)),
                Box2D.Common.Math.b2Math.MulX(xf2, new Box2D.Common.Math.b2Vec2(30 / this.m_physScale, 0)),
                Box2D.Common.Math.b2Math.MulX(xf2, new Box2D.Common.Math.b2Vec2(0, 15 / this.m_physScale))
            ])

            bd = new Box2D.Dynamics.b2BodyDef();
            bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
            bd.fixedRotation = true;

            for(i = 0; i < 5; i++)
            {
                x = 320 + Box2D.Common.Math.b2Math.RandomRange(-3,3);
                bd.position.Set(x / this.m_physScale, (-61.5 + 55 * -i + 300) / this.m_physScale);
                bd.angle = 0;
                body = this.m_world.CreateBody(bd);
                body.CreateFixture2(sd1, 2.0);
                body.CreateFixture2(sd2, 2.0);
            }

            {
                let sd_bottom:Box2D.Collision.Shapes.b2PolygonShape = new Box2D.Collision.Shapes.b2PolygonShape();
                sd_bottom.SetAsBox(45 / this.m_physScale, 4.5 / this.m_physScale);
                
                let sd_left:Box2D.Collision.Shapes.b2PolygonShape = new Box2D.Collision.Shapes.b2PolygonShape();
                sd_left.SetAsOrientedBox(4.5/ this.m_physScale, 81 / this.m_physScale,new Box2D.Common.Math.b2Vec2(-43.5 / this.m_physScale, -70.5 / this.m_physScale), -0.2);

                let sd_right:Box2D.Collision.Shapes.b2PolygonShape = new Box2D.Collision.Shapes.b2PolygonShape();
                sd_right.SetAsOrientedBox(4.5/ this.m_physScale, 81 / this.m_physScale,new Box2D.Common.Math.b2Vec2(43.5 / this.m_physScale, -70.5 / this.m_physScale), 0.2);

                bd = new Box2D.Dynamics.b2BodyDef();
                bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
                bd.position.Set(320 / this.m_physScale, 300 / this.m_physScale);
                body = this.m_world.CreateBody(bd);
                body.CreateFixture2(sd_bottom, 4); 
                body.CreateFixture2(sd_left, 4); 
                body.CreateFixture2(sd_right, 4); 
            }
        }
    }
}